import { request } from 'umi';

/**
* get one record by id
*/
export async function getTakeAwayRuleDetailById(id: number, params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayRuleDetailType.TakeAwayRuleDetailResponse>>(`/api/takeAwayRuleDetail/getById/${id}`, {
        method: 'GET',
        params: params
    });
}

/**
* get all records
*/
export async function getTakeAwayRuleDetailAll(params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayRuleDetailType.TakeAwayRuleDetailResponse>>(`/api/takeAwayRuleDetail/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* get records by page
*/
export async function getTakeAwayRuleDetailPageList(params: object = {}) {
    return request<PageInfo.PageResponse<TakeAwayRuleDetailType.TakeAwayRuleDetailResponse>>(`/api/takeAwayRuleDetail/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* update partial field of record
*/
export async function commonUpdate(id: number, fieldName: string, value: string) {
    return request<ApiResponse.ResultModel<TakeAwayRuleDetailType.TakeAwayRuleDetail>>(`/api/takeAwayRuleDetail/PatchById?id=${id}`, {
        method: 'PATCH',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [{
            "id": id,
            "op": "replace",
            "path": `/${fieldName}`,
            "value": value

        }]
    });
}

/*
* update record
*/
export async function updateTakeAwayRuleDetail(data: TakeAwayRuleDetailType.TakeAwayRuleDetailResponse, params: object = {}) {
    return request<ApiResponse.ResultModel<boolean>>(`/api/takeAwayRuleDetail/put`, {
        method: 'put',
        headers: {
            'Content-Type': 'application/json',
      },
        params:params,
        data: [data],
    });
}

/*
* add one record
*/
export async function addTakeAwayRuleDetail(data: TakeAwayRuleDetailType.TakeAwayRuleDetailResponse, params: object = {}) {
  return request<ApiResponse.ResultModel<TakeAwayRuleDetailType.TakeAwayRuleDetailResponse>>('/api/takeAwayRuleDetail/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    params: params,
    data: [data],
  });
}

export async function deleteTakeAwayRuleDetail(params: DeleteRequest) {
    return request<ApiResponse.ResultModel<boolean>>(`/api/takeAwayRuleDetail/delete`, {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params.id],
    });
}
